import { defineStore } from 'pinia'
import { store } from '/@/store'
import type { AxiosResponse } from 'axios'
import type { Res } from '/@/tool/Res'
import type { Param } from '/@/tool/Param'

import usrService from '/@/api/cn/core/sign/usrService'

import type { Usr } from '/@/model/cn/core/sign/eo/Usr'
import type { UsrQO } from '/@/model/cn/core/sign/qo/UsrQO'
import type { UsrVO } from '/@/model/cn/core/sign/vo/UsrVO'

interface UsrState {
}

export const useUsrStore = defineStore({
  id: 'usr',
  state: (): UsrState => ({
  }),
  getters: {
  },
  actions: {
    save(param: Param<UsrVO>): Promise<Res<UsrVO>> {
      return new Promise<Res<UsrVO>>((resolve, reject) => {
        usrService.save(param).then((res: AxiosResponse<Res<UsrVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    saveBatch(param: Param<Usr>): Promise<Res<Usr>> {
      return new Promise<Res<Usr>>((resolve, reject) => {
        usrService.saveBatch(param).then((res: AxiosResponse<Res<Usr>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    update(param: Param<UsrVO>): Promise<Res<UsrVO>> {
      return new Promise<Res<UsrVO>>((resolve, reject) => {
        usrService.update(param).then((res: AxiosResponse<Res<UsrVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    updateBatch(param: Param<Usr>): Promise<Res<Usr>> {
      return new Promise<Res<Usr>>((resolve, reject) => {
        usrService.updateBatch(param).then((res: AxiosResponse<Res<Usr>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    remove(param: Param<Usr>): Promise<Res<Usr>> {
      return new Promise<Res<Usr>>((resolve, reject) => {
        usrService.remove(param).then((res: AxiosResponse<Res<Usr>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    removeBatch(param: Param<Usr>): Promise<Res<Usr>> {
      return new Promise<Res<Usr>>((resolve, reject) => {
        usrService.removeBatch(param).then((res: AxiosResponse<Res<Usr>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    count(param: Param<UsrQO>): Promise<Res<Usr>> {
      return new Promise<Res<Usr>>((resolve, reject) => {
        usrService.count(param).then((res: AxiosResponse<Res<Usr>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pk(param: Param<UsrQO>): Promise<Res<Usr>> {
      return new Promise<Res<Usr>>((resolve, reject) => {
        usrService.pk(param).then((res: AxiosResponse<Res<Usr>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    query(param: Param<UsrQO>): Promise<Res<Usr>> {
      return new Promise<Res<Usr>>((resolve, reject) => {
        usrService.query(param).then((res: AxiosResponse<Res<Usr>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    paging(param: Param<UsrQO>): Promise<Res<Usr>> {
      return new Promise<Res<Usr>>((resolve, reject) => {
        usrService.paging(param).then((res: AxiosResponse<Res<Usr>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    countVo(param: Param<UsrQO>): Promise<Res<UsrVO>> {
      return new Promise<Res<UsrVO>>((resolve, reject) => {
        usrService.countVo(param).then((res: AxiosResponse<Res<UsrVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pkVo(param: Param<UsrQO>): Promise<Res<UsrVO>> {
      return new Promise<Res<UsrVO>>((resolve, reject) => {
        usrService.pkVo(param).then((res: AxiosResponse<Res<UsrVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    queryVo(param: Param<UsrQO>): Promise<Res<UsrVO>> {
      return new Promise<Res<UsrVO>>((resolve, reject) => {
        usrService.queryVo(param).then((res: AxiosResponse<Res<UsrVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pagingVo(param: Param<UsrQO>): Promise<Res<UsrVO>> {
      return new Promise<Res<UsrVO>>((resolve, reject) => {
        usrService.pagingVo(param).then((res: AxiosResponse<Res<UsrVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
  },
})

export function useUsrStoreWithout() {
  return useUsrStore(store)
}
